package com.example.calculator;

import java.math.BigDecimal;
import java.math.RoundingMode;

public abstract class Actions {

	private static BigDecimal firstBD;
	private static BigDecimal secondBD;

	public static double getAddition(double firstNumber, double secondNumber) {
		firstBD = BigDecimal.valueOf(firstNumber);
		secondBD = BigDecimal.valueOf(secondNumber);
		return (firstBD.add(secondBD)).doubleValue();
	}

	public static double getSubtraction(double firstNumber, double secondNumber) {
		firstBD = BigDecimal.valueOf(firstNumber);
		secondBD = BigDecimal.valueOf(secondNumber);
		return (firstBD.subtract(secondBD)).doubleValue();
	}

	public static double getMultiplication(double firstNumber,
			double secondNumber) {
		firstBD = BigDecimal.valueOf(firstNumber);
		secondBD = BigDecimal.valueOf(secondNumber);
		return (firstBD.multiply(secondBD)).doubleValue();
	}

	public static double getDivision(double firstNumber, double secondNumber)
			throws ArithmeticException {
		if (secondNumber != 0) {
			firstBD = BigDecimal.valueOf(firstNumber);
			secondBD = BigDecimal.valueOf(secondNumber);
			return (firstBD.divide(secondBD, 8, RoundingMode.UP)).doubleValue();
		} else
			throw new ArithmeticException("Can't divide by zero!");
	}

	public static double getSquareRoot(double number)
			throws ArithmeticException {
		if (number >= 0) {
			return Math.sqrt(number);
		} else
			throw new ArithmeticException("Error!");
	}

}
